<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String result = (String) request.getAttribute(StringUtil.RESULT);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<title>注册</title>
</head>
<script type="text/javascript">
	$(function(){
		$btn_submit = $("#submit");
		$registerForm = $("#registerForm");
		$btn_submit.click(function(){
			var name = $("#name").val().trim();
			var psw1 = $("#psw1").val().trim();
			var psw2 = $("#psw2").val().trim();
			var phone = $("#phone").val().trim();
			var email = $("#email").val().trim();
			var IDCard = $("#IDCard").val().trim();
			//判断是否为空值
			if(name == null || name == ""){
				alert("名称不能为空!"); 
				return;
			}
			if(psw1 == null || psw1 == ""){
				alert("密码不能为空!"); 
				return;
			}
			if(phone == null || phone == ""){
				alert("手机号不能为空!"); 
				return;
			}
			if(email == null || email == ""){
				alert("邮箱不能为空!"); 
				return;
			}
			if(IDCard == null || IDCard == ""){
				alert("身份证号不能为空!"); 
				return;
			}
			//判断用户名的长度
			if(name.length <= 3 || name.length > 10){
				alert("用户名长度至少有4个字符, 至多有10个字符!");
				return;
			} 
			//判断是否为手机号
			var reg_phone = /^1[3|4|5|8][0-9]\d{4,8}$/;
			if(!(reg_phone.test(phone))){
				alert("请输入合法手机号!");
				return;
			}
			//判断是否为邮箱号
			var reg_email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			if(!(reg_email.test(email))){
				alert("请输入正确的邮箱号!");
				return;
			}
			//判断是否为身份证号
			var reg_idCard = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;
			if(!(reg_idCard.test(IDCard))){
				alert("请输入正确的身份证号!");
				return;
			}
			//判断密码是否一致
			if(psw1 != psw2){
				alert("密码输入不一致");
				return;
			}
			$registerForm.submit();
		})
	});
</script>
<body>
	<div class="container">
		<%@ include file="/WEB-INF/jsp/include/top.jsp"%>
		<div
			class="margin_top col-lg-6 col-md-6 col-md-push-3 col-xs-12 col-sm-12">
			<form action="user/register" method="post" name="register"
				id="registerForm">
				<table class="table col-lg-12 col-md-12 col-xs-12 col-sm-12">
					<tr>
						<td>用户名:</td>
						<td><input type="text" name="name" id="name"
							placeholder="用户名"></td>
					</tr>
					<tr>
						<td>密码:</td>
						<td><input type="password" name="password" id="psw1"
							placeholder="密码"></td>
					</tr>
					<tr>
						<td>确认密码:</td>
						<td><input type="password" name="" id="psw2"
							placeholder="确认密码"></td>
					</tr>
					<tr>
						<td>联系电话:</td>
						<td><input type="text" name="phone" id="phone"
							placeholder="联系电话"></td>
					</tr>
					<tr>
						<td>邮箱:</td>
						<td><input type="text" name="email" id="email"
							placeholder="邮箱"></td>
					</tr>
					<tr>
						<td>身份证号码:</td>
						<td><input type="text" name="IDCard" id="IDCard"
							placeholder="身份证号码"></td>
					</tr>
					<tr>
						<td>简介:</td>
						<td><input name="description" id="description"
							placeholder="简介"></td>
					</tr>
					<%
						if (result != null) {

							if (result.equals(StringUtil.E_DUPLICATENAME)) {
					%>
					<%=StringUtil.E_DUPLICATENAME%>
					<%
				} else if (result.equals(StringUtil.E_REGISTER)) {
			%>
					<%=StringUtil.E_REGISTER%>
					<%
				}
			%>
					<%
				}
			%>
				</table>
			</form>
			<button id="submit" class="btn submit">注册</button>
		</div>
		<%@ include file="/WEB-INF/jsp/include/bottom.jsp"%>
	</div>
</body>
</html>